<template>
	<view class="my">
		<u-image width="100%" height="266rpx" :src="vuex_baseImgUrl+'my_bg.png'" />
		<view class="login" v-if="vuex_user && vuex_user.type == '1'">
			<view class="left">
				<text class="top">{{vuex_user.name}}</text>
				<text>点击继续完善简历信息</text>
			</view>
			<view class="right">
				<open-data type="userAvatarUrl"></open-data>
			</view>
		</view>

		<view class="no_login" @click="show = true;" v-else>
			<view class="left">
				<text class="top">登录/注册</text>
				<text>点击头像可登录注册</text>
			</view>
			<u-avatar :size="120" src="/static/uview/my/avatar.png" mode="circle"></u-avatar>
		</view>
		<view class="comment">
			<view class="grid">
				<u-grid :col="3" :border="false">
					<u-grid-item @click="handelClick('resume')">
						<u-image width="64rpx" height="64rpx" :src="'/static/uview/my/resume.png'" />
						<view class="grid-text">我的简历</view>
					</u-grid-item>
					<u-grid-item @click="handelClick('adjunct')">
						<u-image width="64rpx" height="64rpx" :src="'/static/uview/my/resume_ accessory.png'" />
						<view class="grid-text">简历附件</view>
					</u-grid-item>
					<u-grid-item @click="handelClick('accept')">
						<u-image width="64rpx" height="64rpx" :src="'/static/uview/my/applicant.png'" />
						<view class="grid-text">我的应聘</view>
					</u-grid-item>

				</u-grid>
			</view>

			<view class="cell">
				<u-cell-group :border="false">
					<u-cell-item :border-bottom="false" title="我的推荐" :title-style="{padding:'0 0 0 30rpx', color:'#333', fontSize:'32rpx'}"
					 :arrow="true" arrow-direction="right">
						<u-icon slot="icon" size="48" name="/static/uview/my/recommend.png"></u-icon>
					</u-cell-item>
				</u-cell-group>
			</view>

			<view v-if="vuex_user && vuex_user.type == '1'">
				<u-button @click="handelClickOut" type="primary" hover-class="none" :custom-style="{background:'#FFFFFF'}">
					<text :style="{margin:'0 0 0 10rpx', color:'#333333'}">退出登录</text>
				</u-button>
			</view>
		</view>

		<u-popup v-model="show" mode="center" width="640rpx" height="516rpx" border-radius="20" closeable="true">
			<view class="login_pop">
				<view>
					<text class="top">登录/注册</text>
					<text>请先注册或登录</text>
				</view>
				<u-button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" type="primary" :custom-style="{margin:'0 0 30rpx 0', background: 'linear-gradient(270deg, #1698F9 0%, #4CC5FC 100%)'}">
					<u-icon size="50" name="/static/uview/my/pop_wx.png"></u-icon>
					<text :style="{margin:'0 0 0 10rpx'}">微信账号快速登录</text>
				</u-button>
				<u-button @click="handelClickMobile" type="default" :custom-style="{border:'2rpx solid #EEEEEE'}">
					<u-icon size="50" :plain="true" name="/static/uview/my/pop_mobile.png"></u-icon>
					<text :style="{margin:'0 0 0 10rpx', color:'#333333'}">手机号注册/登录</text>
				</u-button>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// avatar: `/static/uview/my/avatar.png`,
				show: false,

			}
		},
		onLoad() {

		},

		onShow() {

		},
		methods: {
			getPhoneNumber(result) {
				const {
					detail = {}
				} = result;

				this.show = false;

				if (detail.errMsg == 'getPhoneNumber:ok') {
					//微信快速登录
					const params = {
						"mobile": '13691224349',
						"sms_code": '',
						"wx_open_id": this.vuex_user.wx_open_id, //可选，如果传了，绑定到对应的微信号
						"tenant_id": this.vuex_tenant.id,
						"source": "wx_app::" + detail.encryptedData + ":" + detail.iv,
						"app_id": this.vuex_appId
					}

					console.log(params)

					this.$u.api.getBindMobile(params).then(res => {
						this.$u.vuex('vuex_user', res.user);
						this.$u.vuex('vuex_tenant', res.tenant);
						this.$u.vuex('vuex_token', res.token_type + " " + res.access_token);
					})
				}
			},

			handelClick(type) {
				const {
					vuex_user = {}
				} = this;

				if (vuex_user.type == '0') {
					this.show = true;
					return;
				}

				let url = '';
				switch (type) {

					case 'resume':
						url = 'pages/my_sub/resume/resume'
						break;

					case 'adjunct':
						url = 'pages/my_sub/adjunct/adjunct'
						break;

					case 'accept':
						url = 'pages/my_sub/acceptJob/acceptJob'
						break;

				}
				this.$u.route({
					url: url,
				})
			},

			handelClickMobile() {
				this.$u.route({
					url: 'pages/my_sub/mobileLogin/mobileLogin',
				})
			},

			handelClickOut() {
				const params = {
					"wx_open_id": this.vuex_user.wx_open_id,
					"tenant_id": this.vuex_tenant.id,
					"source": "wx_app",
				}

				this.$u.api.LoginOut(params).then(res => {
					this.$u.route({
						url: 'pages/my_sub/mobileLogin/mobileLogin',
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my {
		position: relative;
		width: 100%;
		height: 100%;
		background: #f9f9f9;

		.login,
		.no_login {
			width: 100%;
			position: absolute;
			top: 0;
			left: 0;
			padding: 48rpx 40rpx 40rpx 48rpx;

			.left {
				width: 300rpx;
				display: inline-block;
				padding: 50rpx 0 0 0;

				text {
					color: #FFFFFF;
					font-size: 26rpx;
					line-height: 36rpx;
				}

				.top {
					display: block;
					font-size: 44rpx;
					line-height: 60rpx;
				}
			}

			.right {
				width: 120rpx;
				height: 120rpx;
				border-radius: 60rpx;
				overflow: hidden;
				float: right;
				margin: 28rpx 0 0 0;
			}

			u-avatar {
				float: right;
				padding: 28rpx 0 0 0;
			}
		}

		.comment {
			width: 100%;
			border-top-right-radius: 24rpx;
			border-top-left-radius: 24rpx;
			background: #FFFFFF;
			position: absolute;
			left: 0;
			top: 226rpx;

			.grid {
				padding: 0 40rpx;
			}

			.cell {
				background: #f9f9f9;
				min-height: 50vh;
			}
		}

		.login_pop {
			padding: 0 48rpx;

			view {
				padding: 64rpx 0;
				text-align: center;

				text {
					color: #666666;
					font-size: 30rpx;
					line-height: 48rpx;
				}

				.top {
					display: block;
					color: #333333;
					font-size: 36rpx;
					line-height: 50rpx;
				}
			}

			u-button {
				margin: 0 0 30rpx 0;
			}
		}
	}
</style>
